home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 March / Pc Users extra 6.iso / pshare95 / prog / formula1 / vcform1.z / Groups.cls < prev    next >
Encoding:
Visual Basic class definition  |  1997-09-08  |  2.4 KB  |  96 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Groups"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
  11. Attribute VB_Ext_KEY = "Top_Level" ,"No"
  12. Attribute VB_Ext_KEY = "Collection" ,"Group"
  13. Attribute VB_Ext_KEY = "Member0" ,"Group"
  14. Option Explicit
  15.  
  16. 'local variable to hold collection
  17. Private mCol As Collection
  18. Public Function Add(Key As String, Name As String, Optional sKey As String) As Group
  19.     'create a new object
  20.     Dim objNewMember As Group
  21.     Set objNewMember = New Group
  22.  
  23.  
  24.     'set the properties passed into the method
  25.     objNewMember.Key = Key
  26.     objNewMember.Name = Name
  27.     objNewMember.Key = Key
  28.     objNewMember.Name = Name
  29.  
  30.  
  31.  
  32.  
  33.     If Len(sKey) = 0 Then
  34.         mCol.Add objNewMember
  35.     Else
  36.         mCol.Add objNewMember, sKey
  37.     End If
  38.  
  39.  
  40.     'return the object created
  41.     Set Add = objNewMember
  42.     Set objNewMember = Nothing
  43.  
  44.  
  45. End Function
  46.  
  47. Public Property Get Item(vntIndexKey As Variant) As Group
  48. Attribute Item.VB_UserMemId = 0
  49.     'used when referencing an element in the collection
  50.     'vntIndexKey contains either the Index or Key to the collection,
  51.     'this is why it is declared as a Variant
  52.     'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
  53.   Set Item = mCol(vntIndexKey)
  54. End Property
  55.  
  56.  
  57.  
  58. Public Property Get Count() As Long
  59.     'used when retrieving the number of elements in the
  60.     'collection. Syntax: Debug.Print x.Count
  61.     Count = mCol.Count
  62. End Property
  63.  
  64.  
  65. Public Sub Remove(vntIndexKey As Variant)
  66.     'used when removing an element from the collection
  67.     'vntIndexKey contains either the Index or Key, which is why
  68.     'it is declared as a Variant
  69.     'Syntax: x.Remove(xyz)
  70.  
  71.  
  72.     mCol.Remove vntIndexKey
  73. End Sub
  74.  
  75.  
  76. Public Property Get NewEnum() As IUnknown
  77. Attribute NewEnum.VB_UserMemId = -4
  78. Attribute NewEnum.VB_MemberFlags = "40"
  79.     'this property allows you to enumerate
  80.     'this collection with the For...Each syntax
  81.     Set NewEnum = mCol.[_NewEnum]
  82. End Property
  83.  
  84.  
  85. Private Sub Class_Initialize()
  86.     'creates the collection when this class is created
  87.     Set mCol = New Collection
  88. End Sub
  89.  
  90.  
  91. Private Sub Class_Terminate()
  92.     'destroys collection when this class is terminated
  93.     Set mCol = Nothing
  94. End Sub
  95.  
  96.